package approve.model;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import models.util.MySqlDataAccessHelper;

public class BuyingFormDAO {
	public static List<BuyingDocument> listBuyingForm(String id,String database) {
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		List<BuyingDocument> lst = new ArrayList<BuyingDocument>();
		try {
			mysql.open(database);
			String sql = "select * from buying_document where document_id = '"+id+"'";
			ResultSet rs = mysql.executeQuery(sql);
			while (rs.next()) {
				lst.add(new BuyingDocument(rs.getString("id"),rs.getString("document_id"),rs.getString("name"),rs.getString("company"),rs.getInt("amount"),rs.getString("unit"),rs.getFloat("price"),rs.getFloat("vat"),rs.getFloat("total")));				
			}
			rs.close();
		} catch (Exception ex){
            ex.printStackTrace();
        }finally {
           mysql.close();
        }
		return lst;
	}
}